package com.test.webchat.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.test.webchat.Pojo.Model.Message;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MessageMapper {
    @Select("SELECT content FROM message WHERE session_id = #{sessionId} ORDER BY post_time DESC LIMIT 1")
    String getLastMassage(Integer sessionId);

    @Select("SELECT message_id,from_id,from_name,session_id,content FROM message " +
            "WHERE session_id = #{sessionId} ORDER BY post_time desc LIMIT 100")
    List<Message> getMessagesBySessionId(Integer sessionId);

    @Insert("INSERT INTO message values (null,#{fromId},#{fromName},#{sessionId},#{content},now())")
    void add(Message message);
}
